package kr.co.mstyleshop.android.activity;

import java.util.ArrayList;
import java.util.Map;

import kr.co.mstyleshop.android.R;
import kr.co.mstyleshop.android.util.BannerImagesJsonSupplier;
import kr.co.mstyleshop.android.util.HttpUtils;
import kr.co.mstyleshop.android.util.ImageDownloader;
import kr.co.mstyleshop.android.util.NetworkUtil;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.webkit.CookieManager;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Toast;
import android.widget.ViewFlipper;

public class MStyleShopWebViewActivity extends Activity implements
		View.OnTouchListener {

	private Button mBtnLogin;
	private Button mBtnLogout;
	private Button mTopBtnSearch;
	private Button mTopBtnOpenmenu;

	private Button mBottomBtnHome;
	private Button mBottomBtnCategory;
	private Button mBottomBtnCart;
	private Button mBottomBtnMypage;
	private Button mBottomBtnCoupon;

	private Button mBtnOpenMenu1;
	private Button mBtnOpenMenu2;
	private Button mBtnOpenMenu3;
	private Button mBtnOpenMenu4;
	private Button mBtnOpenMenu5;
	private Button mBtnOpenMenu6;

	private ImageView mTopLogo;
	private ImageView mBeforeBtn;

	private LinearLayout mTopMenuLayout;
	private LinearLayout mSearchBarLayout;

	private WebView mMyStyleWebView;

	private CookieManager cookieManager;

	// private CheckBox checkBox;
	private ViewFlipper flipper;
	private Button mOpenBtn;
	private LinearLayout mViewerLayout;
	private LinearLayout mDotViewer;
	private LinearLayout mOpenBtnLayout;
	private ProgressBar pb;

	private EditText mSearchValue;
	private Button mSearchBtn;

	// 터치 이벤트 발생 지점의 x좌표 저장
	float xAtDown;
	float xAtUp;

/*	private boolean isStart;
	private static final int FLIP_INTERVAL = 3000;
	private static final int SHOW_NEXT = 0;*/

	private ImageDownloader imageDownloader = new ImageDownloader();
	private ArrayList<Map<String, String>> images;
	
	private int displayW;
	private int displayH;
	
	private InputMethodManager imm;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.m_style_shop);

		boolean isConnected = NetworkUtil.isConnected(this);
		if (!isConnected) {
			Toast.makeText(this, "네트워크 상태를 확인하세요!", Toast.LENGTH_SHORT).show();
			return;
		}

		resourceEventBind();

		initLoginLogout();

		/** 베너이미지 셋팅 */
		new BannerImageInitTask().execute(getString(R.string.domain_url)
				+ getString(R.string.banner_image_url));

	}

	/**
	 * 화면 리소스 초기화
	 */
	private void resourceEventBind() {
		imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
		displayW = display.getWidth();
		displayH = display.getHeight(); 
		
		/** 상단 메뉴 이벤트 */
		mBtnLogin = (Button) findViewById(R.id.top_btn_login);
		mBtnLogin.setOnClickListener(mClickListener);
		mBtnLogout = (Button) findViewById(R.id.top_btn_logout);
		mBtnLogout.setOnClickListener(mClickListener);
		mTopBtnSearch = (Button) findViewById(R.id.top_btn_search);
		mTopBtnSearch.setOnClickListener(mClickListener);
		mTopBtnOpenmenu = (Button) findViewById(R.id.top_btn_openmenu);
		mTopBtnOpenmenu.setOnClickListener(mClickListener);

		mTopLogo = (ImageView) findViewById(R.id.top_logo);
		mTopLogo.setOnClickListener(mClickListener);
		mBeforeBtn = (ImageView) findViewById(R.id.beforeBtn);
		mBeforeBtn.setOnClickListener(mClickListener);

		/** 하단메뉴 이벤트 */
		mBottomBtnHome = (Button) findViewById(R.id.bottom_btn_home);
		mBottomBtnHome.setOnClickListener(mClickListener);
		mBottomBtnCategory = (Button) findViewById(R.id.bottom_btn_category);
		mBottomBtnCategory.setOnClickListener(mClickListener);
		mBottomBtnCart = (Button) findViewById(R.id.bottom_btn_cart);
		mBottomBtnCart.setOnClickListener(mClickListener);
		mBottomBtnMypage = (Button) findViewById(R.id.bottom_btn_mypage);
		mBottomBtnMypage.setOnClickListener(mClickListener);
		mBottomBtnCoupon = (Button) findViewById(R.id.bottom_btn_coupon);
		mBottomBtnCoupon.setOnClickListener(mClickListener);

		/** Open Menu */
		mBtnOpenMenu1 = (Button) findViewById(R.id.openMenu1);
		mBtnOpenMenu1.setOnClickListener(mClickListener);
		mBtnOpenMenu2 = (Button) findViewById(R.id.openMenu2);
		mBtnOpenMenu2.setOnClickListener(mClickListener);
		mBtnOpenMenu3 = (Button) findViewById(R.id.openMenu3);
		mBtnOpenMenu3.setOnClickListener(mClickListener);
		mBtnOpenMenu4 = (Button) findViewById(R.id.openMenu4);
		mBtnOpenMenu4.setOnClickListener(mClickListener);
		mBtnOpenMenu5 = (Button) findViewById(R.id.openMenu5);
		mBtnOpenMenu5.setOnClickListener(mClickListener);
		mBtnOpenMenu6 = (Button) findViewById(R.id.openMenu6);
		mBtnOpenMenu6.setOnClickListener(mClickListener);

		mTopMenuLayout = (LinearLayout) findViewById(R.id.top_menu);
		mSearchBarLayout = (LinearLayout) findViewById(R.id.search_bar);

		mMyStyleWebView = (WebView) findViewById(R.id.mStyleShopWebView);
		mMyStyleWebView.setVerticalScrollbarOverlay(true);
		mMyStyleWebView.clearCache(true);

		WebSettings setting = mMyStyleWebView.getSettings();

		setting.setBuiltInZoomControls(true);
		setting.setJavaScriptEnabled(true);
		setting.setDomStorageEnabled(true);
	    
	    mMyStyleWebView.setWebViewClient(webViewclient);
	    mMyStyleWebView.setWebChromeClient(webChromeClient);
		mMyStyleWebView.loadUrl(getString(R.string.domain_url) + getString(R.string.home_url));
		
		mViewerLayout = (LinearLayout) findViewById(R.id.viewerLayout);
		mDotViewer = (LinearLayout) findViewById(R.id.dotViewer);
		mOpenBtnLayout = (LinearLayout) findViewById(R.id.openBtnLayout);

		// checkBox = (CheckBox)findViewById(R.id.chkAuto);
		// checkBox.setOnCheckedChangeListener(this);

		flipper = (ViewFlipper) findViewById(R.id.viewFlipper);
		flipper.setOnTouchListener(this);

		mOpenBtn = (Button) findViewById(R.id.openBtn);
		mOpenBtn.setOnClickListener(mClickListener);

		mSearchValue = (EditText) findViewById(R.id.searchValue);
		mSearchBtn = (Button) findViewById(R.id.searchBtn);
		mSearchBtn.setOnClickListener(mClickListener);

		pb = (ProgressBar) findViewById(R.id.webViewLoading);

	}

	/**
	 * 로그인 로그아웃 버튼 초기화
	 */
	private void initLoginLogout() {
		new SessionStateTask().execute(getString(R.string.domain_url)
				+ getString(R.string.session_check_url));
	}

	private class BannerImageInitTask extends
			AsyncTask<String, Void, ArrayList<Map<String, String>>> {

		@Override
		protected ArrayList<Map<String, String>> doInBackground(
				String... params) {
			return BannerImagesJsonSupplier.findAllBannerImages(params[0],
					MStyleShopWebViewActivity.this);
		}

		@Override
		protected void onPostExecute(ArrayList<Map<String, String>> result) {
			super.onPostExecute(result);

			if (result != null && !result.isEmpty()) {
				images = result;
				initBannerImages(result);
			}
		}
	}

	/**
	 * 베너이미지 초기화
	 */
	private void initBannerImages(ArrayList<Map<String, String>> images) {

		int currentImgIndex = flipper.getDisplayedChild();

		int height = LayoutParams.WRAP_CONTENT;

		if (!images.isEmpty()) {
			String width = images.get(0).get("width");
			height = new Double(Math.floor((new Double(displayW)/Double.parseDouble(width)) * Double.parseDouble(images.get(0).get("height")))).intValue();
		}
		
		for (Map<String, String> image : images) {
			ImageView bannerImage = new ImageView(this);
			imageDownloader.download(image.get("url"), (ImageView) bannerImage);
			bannerImage.setLayoutParams(new LayoutParams(
					LayoutParams.MATCH_PARENT, height));
			flipper.addView(bannerImage);

			ImageView dotImage = new ImageView(this);
			dotImage.setBackgroundResource(R.drawable.btn_banner_off);
			dotImage.setLayoutParams(new LayoutParams(
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
			mDotViewer.addView(dotImage);
		}

		mDotViewer.getChildAt(currentImgIndex).setBackgroundResource(
				R.drawable.btn_banner_on);
	}

	private class SessionStateTask extends AsyncTask<String, Void, String> {

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			cookieManager = CookieManager.getInstance();
			HttpUtils.cookieId = cookieManager
					.getCookie(getString(R.string.domain_url) + "?agent=mobile");
		}

		@Override
		protected String doInBackground(String... params) {
			return HttpUtils.get(params[0], MStyleShopWebViewActivity.this);
		}

		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			if ("true".equals(result)) {
				mBtnLogin.setVisibility(View.INVISIBLE);
				mBtnLogout.setVisibility(View.VISIBLE);
			} else {
				mBtnLogin.setVisibility(View.VISIBLE);
				mBtnLogout.setVisibility(View.INVISIBLE);
			}
		}
	}

	/**
	 * 현제 WebView에서 페이지 이동
	 */
	WebViewClient webViewclient = new WebViewClient() {

		@Override
		public void onPageStarted(WebView view, String url, Bitmap favicon) {
			super.onPageStarted(view, url, favicon);
			imm.hideSoftInputFromWindow(mSearchValue.getWindowToken(), 0);
			mSearchValue.setText("");
			if (mTopMenuLayout.getVisibility() == View.VISIBLE) {
				mTopMenuLayout.setVisibility(View.INVISIBLE);
			}
			if (mSearchBarLayout.getVisibility() == View.VISIBLE) {
				mSearchBarLayout.setVisibility(View.INVISIBLE);
			}
			pb.setVisibility(View.VISIBLE);
			if(!"http://m.mstyleshop.co.kr/index.html?agent=mobile".equals(url)) {
				mViewerLayout.setVisibility(View.GONE);
				mOpenBtnLayout.setVisibility(View.GONE);
				mTopLogo.setVisibility(View.INVISIBLE);
				mBeforeBtn.setVisibility(View.VISIBLE);
			} else {
				mViewerLayout.setVisibility(View.GONE);
				mOpenBtnLayout.setVisibility(View.VISIBLE);
				mTopLogo.setVisibility(View.VISIBLE);
				mBeforeBtn.setVisibility(View.INVISIBLE);
			}
		}

		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			
			if(url.startsWith("http:") || url.startsWith("https:")) {
				view.loadUrl(url);
			} else {
	            try {
	            	Uri uri = Uri.parse(url);
		            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		            startActivity(intent);
	           	} catch (ActivityNotFoundException ex) {
	            }
			}

			return true;
		}

		@Override
		public void onPageFinished(WebView view, String url) {
			super.onPageFinished(view, url);

			new SessionStateTask().execute(getString(R.string.domain_url) + getString(R.string.session_check_url));
			pb.setVisibility(View.INVISIBLE);
		}
	};

	/**
	 * WebView alert, confirm 창 구현
	 */
	WebChromeClient webChromeClient = new WebChromeClient() {

		@Override
		public boolean onJsAlert(WebView view, String url, String message,
				final JsResult result) {
			new AlertDialog.Builder(view.getContext())
					.setMessage(message)
					.setPositiveButton(android.R.string.ok,
							new AlertDialog.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									result.confirm();
								}
							}).setCancelable(true).create().show();
			return true;
		}

		@Override
		public boolean onJsConfirm(WebView view, String url, String message,
				final JsResult result) {
			new AlertDialog.Builder(view.getContext())
					.setMessage(message)
					.setPositiveButton(android.R.string.ok,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									result.confirm();
								}
							})
					.setNegativeButton(android.R.string.cancel,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									result.cancel();
								}
							}).create().show();
			return true;
		}

		@Override
		public void onProgressChanged(WebView view, int progress) {
			/*
			 * pb.setProgress(progress); if(progress == 100){
			 * pb.setVisibility(View.GONE); }
			 */
		}
	};

	View.OnClickListener mClickListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.top_btn_login:
				bottomMenuInit();
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.login_url));
				mViewerLayout.setVisibility(View.GONE);
				break;

			case R.id.top_btn_logout:
				bottomMenuInit();
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.logout_url));
				break;

			case R.id.top_logo:
				bottomMenuInit();
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.home_url));
				mViewerLayout.setVisibility(View.GONE);
				mOpenBtnLayout.setVisibility(View.VISIBLE);
				break;
				
			case R.id.beforeBtn:
				if (mMyStyleWebView != null && mMyStyleWebView.canGoBack()) {
					mMyStyleWebView.goBack();
				}
				break;

			case R.id.top_btn_search:
				if (mSearchBarLayout.getVisibility() == View.INVISIBLE) {
					mSearchBarLayout.setVisibility(View.VISIBLE);
					
					mSearchValue.requestFocus();
					imm.showSoftInput(mSearchValue, InputMethodManager.SHOW_IMPLICIT);

					if (mTopMenuLayout.getVisibility() == View.VISIBLE) {
						mTopMenuLayout.setVisibility(View.INVISIBLE);
					}

					if (mViewerLayout.getVisibility() == View.VISIBLE) {
						mViewerLayout.setVisibility(View.GONE);
					}
				} else {
					mSearchBarLayout.setVisibility(View.INVISIBLE);
					imm.hideSoftInputFromWindow(mSearchValue.getWindowToken(), 0);
				}
				
				break;
			case R.id.top_btn_openmenu:
				if (mTopMenuLayout.getVisibility() == View.INVISIBLE) {
					mTopMenuLayout.setVisibility(View.VISIBLE);

					if (mSearchBarLayout.getVisibility() == View.VISIBLE) {
						mSearchBarLayout.setVisibility(View.INVISIBLE);
					}

					if (mViewerLayout.getVisibility() == View.VISIBLE) {
						mViewerLayout.setVisibility(View.GONE);
					}
				} else {
					mTopMenuLayout.setVisibility(View.INVISIBLE);
				}

				break;

			case R.id.openBtn:
				if (mViewerLayout.getVisibility() == View.VISIBLE) {
					mViewerLayout.setVisibility(View.GONE);
				} else {
					mViewerLayout.setVisibility(View.VISIBLE);
				}

				break;

			case R.id.searchBtn:
				String value = mSearchValue.getText().toString();
				String url = getString(R.string.domain_url)
						+ getString(R.string.search_url) + "&searchkey="
						+ value;
				mMyStyleWebView.loadUrl(url);

				imm.hideSoftInputFromWindow(mSearchValue.getWindowToken(), 0);

				mSearchValue.setText("");

				break;

			case R.id.bottom_btn_home:
				bottomMenuInit();
				mBottomBtnHome
						.setBackgroundResource(R.drawable.btn_bottom_home2);
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.home_url));
				mOpenBtnLayout.setVisibility(View.VISIBLE);
				mViewerLayout.setVisibility(View.GONE);
				break;

			case R.id.bottom_btn_category:
				bottomMenuInit();
				mBottomBtnCategory
						.setBackgroundResource(R.drawable.btn_bottom_category2);
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.category_url));
				mViewerLayout.setVisibility(View.GONE);
				mOpenBtnLayout.setVisibility(View.GONE);
				break;

			case R.id.bottom_btn_cart:
				bottomMenuInit();
				mBottomBtnCart
						.setBackgroundResource(R.drawable.btn_bottom_bang2);
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.cart_url));
				mViewerLayout.setVisibility(View.GONE);
				mOpenBtnLayout.setVisibility(View.GONE);
				break;

			case R.id.bottom_btn_mypage:
				bottomMenuInit();
				mBottomBtnMypage
						.setBackgroundResource(R.drawable.btn_bottom_mypage2);
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.mypage_url));
				mViewerLayout.setVisibility(View.GONE);
				mOpenBtnLayout.setVisibility(View.GONE);
				break;

			case R.id.bottom_btn_coupon:
				bottomMenuInit();
				mBottomBtnCoupon
						.setBackgroundResource(R.drawable.btn_bottom_coupon2);
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.coupon_url));
				mViewerLayout.setVisibility(View.GONE);
				mOpenBtnLayout.setVisibility(View.GONE);
				break;

			case R.id.openMenu1:
				bottomMenuInit();
				mBottomBtnCategory
						.setBackgroundResource(R.drawable.btn_bottom_category2);
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.category_url));
				break;

			case R.id.openMenu2:
				bottomMenuInit();
				mBottomBtnCart
						.setBackgroundResource(R.drawable.btn_bottom_bang2);
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.cart_url));
				break;

			case R.id.openMenu3:
				bottomMenuInit();
				mBottomBtnMypage
						.setBackgroundResource(R.drawable.btn_bottom_mypage2);
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.mypage_url));
				break;

			case R.id.openMenu4:
				bottomMenuInit();
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.orderlist_url));
				break;

			case R.id.openMenu5:
				bottomMenuInit();
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.bankbook_url));
				break;

			case R.id.openMenu6:
				bottomMenuInit();
				mMyStyleWebView.loadUrl(getString(R.string.domain_url)
						+ getString(R.string.qna_url));
				mTopMenuLayout.setVisibility(View.INVISIBLE);
				break;
			}
		}
	};

	private void bottomMenuInit() {
		mBottomBtnHome.setBackgroundResource(R.drawable.selector_home_btn);
		mBottomBtnCategory
				.setBackgroundResource(R.drawable.selector_category_btn);
		mBottomBtnCart.setBackgroundResource(R.drawable.selector_cart_btn);
		mBottomBtnMypage.setBackgroundResource(R.drawable.selector_mypage_btn);
		mBottomBtnCoupon.setBackgroundResource(R.drawable.selector_coupon_btn);
	}

	@Override
	public void onBackPressed() {
		if (mMyStyleWebView != null && mMyStyleWebView.canGoBack()) {
			mMyStyleWebView.goBack();
		} else {
			super.onBackPressed();
		}
	}

/*	@Override
	public void onCheckedChanged(CompoundButton view, final boolean isChecked) {
		// Log.w("checked", Boolean.toString(isChecked));

		
		 * if(isChecked == true) { // 왼쪽 에니메이션 설정
		 * flipper.setInAnimation(AnimationUtils.loadAnimation(this,
		 * R.anim.push_left_in));
		 * flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
		 * R.anim.push_left_out));
		 * 
		 * // 자동 Flipping 시작 (간격 3초) flipper.setFlipInterval(3000);
		 * flipper.startFlipping();
		 * 
		 * isStart = true; } else { // 자동 Flipping 해지 flipper.stopFlipping();
		 * isStart = false; }
		 * 
		 * new Thread(new AtuoImagesFlipperRunner()).start();
		 

	}*/

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// 터치 이벤트가 일어난 뷰가 ViewFlipper가 아니면 return
		if (v != flipper)
			return false;

		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			xAtDown = event.getX(); // 터치 시작지점 x좌표 저장
		} else if (event.getAction() == MotionEvent.ACTION_UP) {
			xAtUp = event.getX(); // 터치 끝난지점 x좌표 저장

			if ((xAtDown - xAtUp) < 10 && (xAtDown - xAtUp) > -10) {
				Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(images
						.get(flipper.getDisplayedChild()).get("link")));
				startActivity(intent);
			}

			if ((xAtDown - xAtUp) > 10) {
				// 왼쪽 방향 에니메이션 지정
				flipper.setInAnimation(AnimationUtils.loadAnimation(this,
						R.anim.push_left_in));
				flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
						R.anim.push_left_out));

				// 다음 view 보여줌
				mDotViewer.getChildAt(flipper.getDisplayedChild())
						.setBackgroundResource(R.drawable.btn_banner_off);
				flipper.showNext();
				mDotViewer.getChildAt(flipper.getDisplayedChild())
						.setBackgroundResource(R.drawable.btn_banner_on);
			} else if ((xAtDown - xAtUp) < -10) {
				// 오른쪽 방향 에니메이션 지정
				flipper.setInAnimation(AnimationUtils.loadAnimation(this,
						R.anim.push_right_in));
				flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
						R.anim.push_right_out));
				// 전 view 보여줌
				mDotViewer.getChildAt(flipper.getDisplayedChild())
						.setBackgroundResource(R.drawable.btn_banner_off);
				flipper.showPrevious();
				mDotViewer.getChildAt(flipper.getDisplayedChild())
						.setBackgroundResource(R.drawable.btn_banner_on);
			}
		}
		return true;
	}

/*	private class AtuoImagesFlipperRunner implements Runnable {

		@Override
		public void run() {
			while (isStart) {
				Message m = new Message();
				m.what = SHOW_NEXT;
				myViewUpdateHandler.sendMessage(m);
				try {
					Thread.sleep(FLIP_INTERVAL);
				} catch (InterruptedException e) {
				}
			}
		}
	}

	Handler myViewUpdateHandler = new Handler() {
		// @Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case SHOW_NEXT:
				mDotViewer.getChildAt(flipper.getDisplayedChild())
						.setBackgroundResource(R.drawable.btn_banner_off);

				flipper.showNext();

				mDotViewer.getChildAt(flipper.getDisplayedChild())
						.setBackgroundResource(R.drawable.btn_banner_on);
				break;
			}
			super.handleMessage(msg);
		}
	};*/
}